using ASP;
using HoWave.Web;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.IO;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Shop_Browse_browse_offer : Shop, IRequiresSessionState
{
	protected ScriptManager ScriptManager1;
	protected Label Reuqest_Class;
	protected Label TxtClassID;
	protected Label TxtClassName;
	protected UpdatePanel UpdatePanel2;
	protected Label ProductCount;
	protected UpdatePanel UpdatePanel4;
	protected DropDownList F_ProductPlace;
	protected GridView GridView1;
	protected ObjectDataSource ObjectDataSource1;
	protected UpdatePanel UpdatePanel1;
	protected ObjectDataSource ObjectDataSource5;
	protected TextBox TxtRequestTitle;
	protected TreeView TreeView1;
	protected HtmlForm form_1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_PreInit(object sender, EventArgs e)
	{
		try
		{
			Template.BindTemplateToPage(this.Page, "Browseoffer");
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (base.Request["ClassID"] != null && base.Request["ClassID"] != "")
			{
				this.TxtClassID.Text = base.Request["ClassID"];
			}
			if (base.Request["ClassName"] != null && base.Request["ClassName"] != "")
			{
				this.TxtClassName.Text = base.Request["ClassName"];
			}
			if (base.Request["RequestTitle"] != null && base.Request["RequestTitle"] != "")
			{
				this.TxtRequestTitle.Text = base.Request["RequestTitle"];
			}
			if (base.Request["ProductPlace"] != null && base.Request["ProductPlace"] != "")
			{
				this.F_ProductPlace.SelectedValue = base.Request["ProductPlace"];
			}
			this.BandRequest_Class();
			this.BindTree();
		}
		this.GetRequestCount();
	}
	protected void GetRequestCount()
	{
		Shop_Request shop_Request = new Shop_Request();
		DataTable getRequestListBySQL = shop_Request.GetGetRequestListBySQL("", this.TxtClassID.Text, this.F_ProductPlace.SelectedValue, "-1", "0", this.TxtRequestTitle.Text);
		this.ProductCount.Text = "共" + getRequestListBySQL.Rows.Count.ToString() + "件求购商品";
	}
	public void BindTree()
	{
		Shop_Class shop_Class = new Shop_Class();
		this.TreeView1.Nodes.Clear();
		DataTable allClass = shop_Class.GetAllClass();
		string text = this.TxtClassID.Text;
		string text2 = this.TxtClassName.Text;
		TreeNode treeNode = new TreeNode();
		treeNode.Text = text2;
		treeNode.Value = text;
		treeNode.Expanded = new bool?(true);
		this.TreeView1.Nodes.Add(treeNode);
		this.CreateChildNode(treeNode, allClass);
	}
	public void CreateChildNode(TreeNode parentnode, DataTable dataTable)
	{
		DataRow[] array = dataTable.Select("ParentID=" + parentnode.Value);
		DataRow[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			DataRow dataRow = array2[i];
			TreeNode treeNode = new TreeNode();
			treeNode.Text = dataRow["ClassName"].ToString();
			treeNode.Value = dataRow["ClassID"].ToString();
			if (dataRow["ParentID"].ToString() == this.TxtClassID.Text && this.TxtClassID.Text != "0")
			{
				treeNode.Expanded = new bool?(true);
			}
			else
			{
				treeNode.Expanded = new bool?(false);
			}
			parentnode.ChildNodes.Add(treeNode);
			this.CreateChildNode(treeNode, dataTable);
		}
	}
	protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
	{
		this.TxtClassID.Text = this.TreeView1.SelectedNode.Value;
		this.TxtClassName.Text = this.TreeView1.SelectedNode.Text;
		this.BandRequest_Class();
		this.GetRequestCount();
	}
	protected void BandRequest_Class()
	{
		this.Reuqest_Class.Text = string.Concat(new string[]
		{
			"<a href=\"browse_offer.aspx?ClassName=",
			base.Server.UrlEncode("所有种类"),
			"&ClassID=0&RequestTitle=",
			base.Server.UrlEncode(this.TxtRequestTitle.Text),
			"&ProductPlace=",
			base.Server.UrlEncode(this.F_ProductPlace.SelectedValue),
			"\">所有种类</a>->"
		});
		string text = "";
		int classID = int.Parse(this.TxtClassID.Text);
		Shop_Class shop_Class = new Shop_Class();
		DataTable classByClassID = shop_Class.GetClassByClassID(classID);
		if (classByClassID.Rows.Count > 0)
		{
			text = text + classByClassID.Rows[0]["parentpath"].ToString() + "," + classID.ToString();
		}
		string[] array = text.Split(new char[]
		{
			','
		});
		for (int i = 0; i < array.Length; i++)
		{
			if (array[i] != "")
			{
				DataTable classByClassID2 = shop_Class.GetClassByClassID(int.Parse(array[i]));
				if (classByClassID2.Rows.Count > 0)
				{
					Label expr_185 = this.Reuqest_Class;
					string text2 = expr_185.Text;
					expr_185.Text = string.Concat(new string[]
					{
						text2,
						"<a href=\"browse_offer.aspx?ClassName=",
						classByClassID2.Rows[0]["ClassName"].ToString(),
						"&ClassID=",
						classByClassID2.Rows[0]["ClassID"].ToString(),
						"&RequestTitle=",
						base.Server.UrlEncode(this.TxtRequestTitle.Text),
						"&ProductPlace=",
						base.Server.UrlEncode(this.F_ProductPlace.SelectedValue),
						"\">",
						classByClassID2.Rows[0]["classname"].ToString(),
						"</a>->"
					});
				}
			}
		}
		if (this.Reuqest_Class.Text.Contains("->"))
		{
			this.Reuqest_Class.Text = this.Reuqest_Class.Text.Remove(this.Reuqest_Class.Text.Length - 2);
		}
	}
	protected void GridView1_DataBound(object sender, EventArgs e)
	{
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			Image image = (Image)gridViewRow.FindControl("RequestImg");
			if (!File.Exists(base.Server.MapPath(image.ImageUrl.Replace("/", "\\"))))
			{
				image.ImageUrl = "Images/show_nopic.gif";
			}
			bool flag = false;
			bool flag2 = false;
			DataRow shopconfig = base.shopconfig;
			if (shopconfig["ShowQQ"].ToString() == "1")
			{
				flag = true;
			}
			if (shopconfig["ShowWW"].ToString() == "1")
			{
				flag2 = true;
			}
			Image image2 = (Image)gridViewRow.FindControl("QQImage");
			if (flag && image2.ImageUrl != "")
			{
				image2.ImageUrl = "http://wpa.qq.com/pa?p=1:" + image2.ImageUrl + ":4";
			}
			else
			{
				image2.Visible = false;
			}
			Image image3 = (Image)gridViewRow.FindControl("TaobaoImage");
			if (flag2 && image3.ImageUrl != "")
			{
				image3.ImageUrl = "http://amos1.taobao.com/online.ww?v=2&amp;uid=" + base.Server.UrlEncode(image3.ImageUrl) + "&s=2";
				HyperLink hyperLink = (HyperLink)gridViewRow.FindControl("TaobaoLink");
				hyperLink.NavigateUrl = "http://amos1.taobao.com/msg.ww?v=2&amp;uid=" + base.Server.UrlEncode(hyperLink.NavigateUrl) + "&s=2";
			}
			else
			{
				image3.Visible = false;
			}
		}
	}
	protected void TxtRequestTitle_TextChanged(object sender, EventArgs e)
	{
		this.GetRequestCount();
	}
	protected void F_ProductPlace_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.GetRequestCount();
	}
}
